/*
 * @(#) $Header$
 *
 * Copyright (C) 2009  Daniel Léonard
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package ca.forklabs.baselib.util;

/**
 * Class {@code ObjectUtil} provides useful methods acting on objects.
 *
 * @author   <a href="mailto:forklabs at gmail.com?subject=ca.forklabs.util.ObjectUtil">Daniel Léonard</a>
 * @version $Revision$
 */
public class ObjectUtil {

//---------------------------
// Constructor
//---------------------------

   /**
    * Only allow subclass factories.
    */
   protected ObjectUtil() {
   // nothing
      }


//---------------------------
// Class methods
//---------------------------

   /**
    * Determines if the two objects are equals. Two objects are equals if both
    * are {@code null} or if {@code o1.equals(o2)} returns {@code true}.
    * @param   o1   the first object.
    * @param   o2   the second object.
    * @return   {@code true} if the objects are equals, {@code false} otherwise.
    */
   public static boolean areEquals(Object o1, Object o2) {
      boolean are_equal = ((null == o1) ? (null == o2) : o1.equals(o2));
      return are_equal;
      }

   /**
    * Determines if the two objects are the same. Two objects are the same if
    * the comparison operator {@code ==} says the objects are equal.
    * @param   o1   the first object.
    * @param   o2   the second object.
    * @return   {@code true} if the objects are the same, {@code false}
    *           otherwise.
    */
   public static boolean areSame(Object o1, Object o2) {
      boolean are_same = (o1 == o2);
      return are_same;
      }

   /**
    * Calls {@code hashCode} if the object is not {@code null}.
    * @param   o   the object.
    * @return   the hash code if the object is not {@code null}, 0 otherwise.
    */
   public static int hashCode(Object o) {
      int code = (null == o) ? 0 : o.hashCode();
      return code;
      }

   /**
    * Calls {@code toString} if the object is not {@code null}.
    * @param   o   the object.
    * @return   the string representation if the object is not {@code null},
    *           {@code null} otherwise.
    */
   public static String toString(Object o) {
      String s = (null == o) ? null : o.toString();
      return s;
      }

   }
